﻿<%@ page contentType="text/html;charset=UTF-8" language="java" %>
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
        <c:set var="ctx" value="${pageContext.request.contextPath}" />
        <html>

        <head>
            <link rel="stylesheet" href="${ctx}/common/common.css">
            <link rel="stylesheet" href="${ctx}/common/plugins/layuiadmin/layui/css/layui.css" media="all">
            <link rel="stylesheet" href="${ctx}/common/plugins/layuiadmin/style/admin.css" media="all">
            <script src="${ctx}/common/plugins/layuiadmin/layui/layui.js"></script>

            <style>
                .layui-table-header {
                    width: 100%;
                }

                .layui-products {
                    border-bottom: 2px solid #e7e7e7;
                    /*border-top: 2px solid #e7e7e7;*/
                    margin: 10px 0px;
                    padding: 5px 0px;
                }

                .layui-products_li {
                    margin-left: 50px;
                    border-bottom: 1px dashed #e7e7e7;
                }

                .layui-products_li:first-child {
                    border: none;
                }

                .layui-col-md4 img {
                    margin-right: 5px;
                    width: 22px;
                    height: 22px;
                }

                .layui-col-md4 img {
                    margin-right: 5px;
                    width: 22px;
                    height: 22px;
                }

                .layui-unselect.layui-form-select {
                    width: 100%;
                }
            </style>
        </head>

        <body>
            <!--主体内容层-->
            <div class="layui-fluid">
                <div class="layui-row">
                    <div class="layui-col-xs12">
                        <form class="layui-form">
                            <!--输入框内容盒子-->
                            <div class="layui-col-xs12">
                                <!--输入框-->
                                <div class="layui-col-xs6">
                                    <label class="layui-form-label">产品名称</label>
                                    <div class="layui-input-block">
                                        <input type="text" name="sourceName2" id="sourceName2" required
                                            lay-verify="required" placeholder="请输入产品名称" autocomplete="off"
                                            class="layui-input">
                                    </div>
                                </div>
                                <div class="layui-col-xs6">
                                    <label class="layui-form-label">产品类型</label>
                                    <div class="layui-input-block">
                                        <select id="pType2" name="pType2" value="1">
                                            <c:forEach items="${codeList }" var="obj">
                                                <option value="${obj.code }">${obj.described }</option>
                                            </c:forEach>
                                        </select>
                                    </div>
                                </div>
                            </div>
                            <!-- <div class="layui-col-xs12">
                	<div class="layui-col-md5">
				        <label class="layui-form-label">生产状态</label>
				        <div class="layui-input-block">
				        	<select name="productStat">
			        			<option value="0" selected="">停产</option>
			        			<option value="1">正常</option>
							</select>
				        </div>
				    </div>
				<div class="layui-col-xs12"> -->
                            <!--通用按钮盒子-->
                            <div class="layui-col-xs12" style="padding-top: 10px;padding-bottom: 10px">
                                <div style="float: right;" class="layui-btn-group paramBtn">
                                    <button data-type="reloadSource" type="button"
                                        class="layui-btn layui-btn-sm layui-btn-danger">
                                        查询
                                    </button>
                                    <button data-type="resetSource" type="reset"
                                        class="layui-btn layui-btn-sm layui-btn-danger">
                                        重置
                                    </button>
                                </div>
                            </div>
                        </form>
                        <!--通用table表格-->
                        <table class="layui-table" id="sourceReload"
                            lay-data="{ url:'${ctx }/inspStandard/querySourceList',page:true,groups:5}"
                            lay-filter="demo">
                            <thead>
                                <tr>
                                    <th lay-data="{field:'sourceName'}">产品名称</th>
                                    <th lay-data="{field:'specifications'}">规格</th>
                                    <th lay-data="{field:'unit'}">单位</th>
                                    <th lay-data="{field:'right',toolbar:'#barDemo'}">操作</th>
                                </tr>
                            </thead>
                        </table>
                    </div>
                </div>
            </div>
            <script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="select">选择</a>
</script>
        </body>
        <script>
            layui.use('table', function () {
                var loading = layer.msg("数据加载中...");
                var table = layui.table;
                table.render({
                    done: function () {
                        layer.close(loading);
                    }
                })
                //监听filter为demo的table中的工具条
                table.on('tool(demo)', function (obj) {
                    var data = obj.data;
                    if (obj.event === 'select') {
                        $('#sourceId', parent.document).val(data.id);
                        $('#sourceName', parent.document).val(data.sourceName);
                        $('#specifications', parent.document).val(data.specifications);
                        $('#sourceUnit', parent.document).val(data.unit);
                        $('#type', parent.document).val($("#pType2").val());
                        var index = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(index);
                    }
                });

                var $ = layui.$, active = {
                    reloadSource: function () {//条件查询
                        var sourceName = document.getElementById("sourceName2").value;
                        var pType = document.getElementById("pType2").value;
                        table.reload('sourceReload', {
                            where: {
                                sourceName: sourceName,
                                pType: pType
                            }
                        });
                    },
                    resetSource: function () {
                        table.reload('sourceReload', {
                            where: {
                                sourceName: '',
                                pType: '1'
                            }
                        })
                    }
                };

                $('.demoTable .layui-btn').on('click', function () {
                    var type = $(this).data('type');
                    active[type] ? active[type].call(this) : '';
                });
                //给按钮绑定active中的方法
                $(".paramBtn .layui-btn").on("click", function () {
                    var type = $(this).data('type');
                    //查看是active这个json中是否有type这个方法，如果有调用，如果没有不知心；
                    active[type] ? active[type].call() : '';
                })

            });
        </script>
        </body>

        </html>